
let webpack = require('webpack')
let base = require('./base')
let { merge } = require('webpack-merge')
let path = require('path')
let mock = require('../mock')
module.exports = merge(base, {
  mode: 'development',
  plugins: [
    new webpack.DefinePlugin({
      BASE: JSON.stringify("/api")
    })
  ],
  devServer: {
    // 所有的开发设置 只针对开发有作用  生产不起任何u哦用
    port: 3000, // 设置的是服务的端口号 默认是8080
    open: {
      app: {
        name: 'chrome',
      },
    },// 服务启动之后是否自动打开浏览器
    devMiddleware: {
      writeToDisk: true,// 告诉webpack 服务 启动的时候 内容写入硬盘
    },
    hot: true,
    static: {
      // 把data文件夹当作一个静态服务文件
      directory: path.resolve(__dirname, '../data'),
    },
    compress: true,// 开启gzip压缩
    proxy: {
      // 只能解决开发环境下的配置
      // '/api': 'http://localhost:9999',
      // '/p2p': "https://www.renrendai.com"
      '/p2p': {
        target: "https://www.renrendai.com",
        changeOrigin: true,
      },
      "/api": {
        //   /api/q    http://localhost:9999/q
        target: 'http://localhost:9999',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    },
    onBeforeSetupMiddleware: function (devServer) {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined');
      }
      mock(devServer.app)
    },
  },
  // devtool: 'source-map'
  devtool: 'eval-cheap-module-source-map'
  // devtool: 'eval-source-map'
})